import { Router } from 'express';
import { ClientVenueController } from '../../api/controllers/venueController';
import { authenticateClient } from '../../middleware/auth';

const router = Router();
const venueController = new ClientVenueController();

/**
 * @swagger
 * /api/client/venues:
 *   get:
 *     summary: 获取场地列表（前端应用专用）
 *     tags: [客户端场地]
 *     parameters:
 *       - in: query
 *         name: page
 *         schema:
 *           type: integer
 *           default: 1
 *         description: 页码
 *       - in: query
 *         name: limit
 *         schema:
 *           type: integer
 *           default: 20
 *         description: 每页数量
 *       - in: query
 *         name: city
 *         schema:
 *           type: string
 *         description: 城市筛选
 *       - in: query
 *         name: country
 *         schema:
 *           type: string
 *         description: 国家筛选
 *       - in: query
 *         name: status
 *         schema:
 *           type: string
 *           default: ACTIVE
 *         description: 状态筛选
 *       - in: query
 *         name: sortBy
 *         schema:
 *           type: string
 *           enum: [sortOrder, name, createdAt, city]
 *           default: sortOrder
 *         description: 排序字段 (sortOrder-按排序字段, name-按名称, createdAt-按创建时间, city-按城市)
 *       - in: query
 *         name: sortOrder
 *         schema:
 *           type: string
 *           enum: [asc, desc]
 *           default: asc
 *         description: 排序方向
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取场地列表成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     venues:
 *                       type: array
 *                       items:
 *                         type: object
 *                         properties:
 *                           id:
 *                             type: integer
 *                           name:
 *                             type: string
 *                           description:
 *                             type: string
 *                           address:
 *                             type: string
 *                           city:
 *                             type: string
 *                           country:
 *                             type: string
 *                           status:
 *                             type: string
 *                           capacity:
 *                             type: integer
 *                           floorCount:
 *                             type: integer
 *                           performanceCount:
 *                             type: integer
 *                           createdAt:
 *                             type: string
 *                           updatedAt:
 *                             type: string
 *                     pagination:
 *                       type: object
 *                       properties:
 *                         total:
 *                           type: integer
 *                         page:
 *                           type: integer
 *                         limit:
 *                           type: integer
 *                         totalPages:
 *                           type: integer
 */
router.get('/', authenticateClient, venueController.getVenueList);

/**
 * @swagger
 * /api/client/venues/cities:
 *   get:
 *     summary: 获取城市列表
 *     tags: [客户端场地]
 *     parameters:
 *       - in: query
 *         name: country
 *         schema:
 *           type: string
 *         description: 国家筛选（可选）
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取城市列表成功
 *                 data:
 *                   type: array
 *                   items:
 *                     type: object
 *                     properties:
 *                       city:
 *                         type: string
 *                       venueCount:
 *                         type: integer
 */
router.get('/cities', authenticateClient, venueController.getCityList);

/**
 * @swagger
 * /api/client/venues/countries:
 *   get:
 *     summary: 获取国家列表
 *     tags: [客户端场地]
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取国家列表成功
 *                 data:
 *                   type: array
 *                   items:
 *                     type: object
 *                     properties:
 *                       country:
 *                         type: string
 *                       venueCount:
 *                         type: integer
 */
router.get('/countries', authenticateClient, venueController.getCountryList);

/**
 * @swagger
 * /api/client/venues/search:
 *   get:
 *     summary: 搜索场地
 *     tags: [客户端场地]
 *     parameters:
 *       - in: query
 *         name: keyword
 *         schema:
 *           type: string
 *         description: 搜索关键字
 *       - in: query
 *         name: page
 *         schema:
 *           type: integer
 *         description: 页码
 *       - in: query
 *         name: pageSize
 *         schema:
 *           type: integer
 *         description: 每页数量
 *       - in: query
 *         name: city
 *         schema:
 *           type: string
 *         description: 城市筛选
 *       - in: query
 *         name: country
 *         schema:
 *           type: string
 *         description: 国家筛选
 *       - in: query
 *         name: sortBy
 *         schema:
 *           type: string
 *           enum: [sortOrder, name, createdAt, city]
 *           default: sortOrder
 *         description: 排序字段 (sortOrder-按排序字段, name-按名称, createdAt-按创建时间, city-按城市)
 *       - in: query
 *         name: sortOrder
 *         schema:
 *           type: string
 *           enum: [asc, desc]
 *           default: asc
 *         description: 排序方向
 *     responses:
 *       200:
 *         description: 搜索成功
 */
router.get('/search', authenticateClient, venueController.searchVenues);

/**
 * @swagger
 * /api/client/venues/{id}:
 *   get:
 *     summary: 获取场馆详情
 *     tags: [客户端场地]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         schema:
 *           type: integer
 *         description: 场馆ID
 *     responses:
 *       200:
 *         description: 获取成功
 *       400:
 *         description: 无效的场馆ID
 *       404:
 *         description: 场馆不存在
 */
router.get('/:id', authenticateClient, venueController.getVenueById);

/**
 * @swagger
 * /api/client/venues/popular:
 *   get:
 *     summary: 获取热门场馆
 *     tags: [客户端场地]
 *     parameters:
 *       - in: query
 *         name: limit
 *         schema:
 *           type: integer
 *         description: 返回数量限制
 *     responses:
 *       200:
 *         description: 获取成功
 */
router.get('/popular', authenticateClient, venueController.getPopularVenues);

/**
 * @swagger
 * /api/client/venues/{venueId}/floors:
 *   get:
 *     summary: 根据场馆获取楼层列表
 *     tags: [客户端场地]
 *     parameters:
 *       - in: path
 *         name: venueId
 *         required: true
 *         schema:
 *           type: integer
 *         description: 场馆ID
 *       - in: query
 *         name: status
 *         schema:
 *           type: string
 *           default: ACTIVE
 *           enum: [ACTIVE, INACTIVE]
 *         description: 楼层状态
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取场馆楼层列表成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     venue:
 *                       type: string
 *                       description: 场馆名称
 *                     venueInfo:
 *                       type: object
 *                       description: 场馆详细信息
 *                       properties:
 *                         id:
 *                           type: integer
 *                         name:
 *                           type: string
 *                         description:
 *                           type: string
 *                         address:
 *                           type: string
 *                         city:
 *                           type: string
 *                         country:
 *                           type: string
 *                     floors:
 *                       type: array
 *                       description: 楼层列表
 *                       items:
 *                         type: object
 *                         properties:
 *                           id:
 *                             type: integer
 *                           venueId:
 *                             type: integer
 *                           venue:
 *                             type: string
 *                           name:
 *                             type: string
 *                           level:
 *                             type: integer
 *                           description:
 *                             type: string
 *                           floorPlanUrl:
 *                             type: string
 *                           status:
 *                             type: string
 *                           performanceCount:
 *                             type: integer
 *                           hasActivePerformances:
 *                             type: boolean
 *                     totalFloors:
 *                       type: integer
 *                       description: 楼层总数
 *       400:
 *         description: 场馆ID不能为空或无效的场馆ID
 *       404:
 *         description: 场馆不存在或已停用
 */
router.get('/:venueId/floors', authenticateClient, venueController.getFloorsByVenue);

/**
 * @swagger
 * /api/client/venues/{venueId}/floors/stats:
 *   get:
 *     summary: 获取场馆楼层统计信息
 *     tags: [客户端场地]
 *     parameters:
 *       - in: path
 *         name: venueId
 *         required: true
 *         schema:
 *           type: integer
 *         description: 场馆ID
 *     responses:
 *       200:
 *         description: 获取成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: 获取场馆楼层统计信息成功
 *                 data:
 *                   type: object
 *                   properties:
 *                     venueId:
 *                       type: integer
 *                     venueName:
 *                       type: string
 *                     totalFloors:
 *                       type: integer
 *                       description: 总楼层数
 *                     activeFloors:
 *                       type: integer
 *                       description: 活跃楼层数
 *                     inactiveFloors:
 *                       type: integer
 *                       description: 非活跃楼层数
 *                     floorsWithPerformances:
 *                       type: integer
 *                       description: 有演出的楼层数量
 *                     levelDistribution:
 *                       type: array
 *                       description: 楼层层级分布
 *                       items:
 *                         type: object
 *                         properties:
 *                           level:
 *                             type: integer
 *                             description: 楼层层级
 *                           count:
 *                             type: integer
 *                             description: 该层级的楼层数量
 *       400:
 *         description: 场馆ID不能为空或无效的场馆ID
 *       404:
 *         description: 场馆不存在或已停用
 */
router.get('/:venueId/floors/stats', authenticateClient, venueController.getVenueFloorStats);

export default router;
